﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace IIS根据9期更改版
{
    public class HttpApplication : IHttpHandler
    {
        public void ProcessRequest(HttpContent content)
        {
            //获得请求信息
            //content.HttpRequest.HttpMethod
            //获得你请求的文件
            string BaseStr = AppDomain.CurrentDomain.BaseDirectory;
            string fileName = Path.Combine(BaseStr, content.HttpRequest.Url.TrimStart('/'));
            string ext = Path.GetExtension(fileName);
            if (ext==".asp")
            {
                var classname = Path.GetFileNameWithoutExtension(fileName);
               IHttpHandler obj=   (IHttpHandler) Assembly.Load("IIS根据9期更改版").CreateInstance("IIS根据9期更改版." + classname);//一定要是全名称;
                obj.ProcessRequest(content);
                return;
             
            }
            if (!File.Exists(fileName))
            {
                content.HttpResponse.StateCode = "404";
                content.HttpResponse.StateDes = "找不到网页";
                content.HttpResponse.ContentType = "text/html";
                content.HttpResponse.Body = File.ReadAllBytes(BaseStr + "404.html");
            }
            else
            {
                content.HttpResponse.StateCode = "200";
                content.HttpResponse.StateDes = "OK";
                content.HttpResponse.ContentType = "text/html";
                content.HttpResponse.Body = File.ReadAllBytes(fileName);



            }
        }
    }
}
